4. 演習4: 回帰分析#

適切な題材を選び、回帰モデルを学習せよ。ただし、以下の観点で採点を行うので、これらを満たすように解答せよ。

4.1. タスクの説明#

近似値によってマクローリン展開の係数を求める回帰モデルを実装した。 特に\(\frac{1}{1+x}, e^x\)のマクローリン展開について、8次までの係数を求めることを検討する。

それぞれ、収束半径内ではマクローリン展開可能であり、

(4.1)#\[\begin{align} \frac{1}{1- x} &= \sum_{n=0}^{\infty} x^n \quad (|x|<1)\\ e^x &= \sum_{n=0}^{\infty} \frac{1}{n!}x^n \quad (|x|<\infty) \end{align}\]

となる。

今回の回帰では、8次で近似することを考え、重み\(\boldsymbol{w}\)が上式の値に近づいているかどうかを確認する。

よって入力は

  1. \(\frac{1}{1-x}\)\(x \in [0,0.9]\)の実数

  2. \(e^x\)については\(x \in [0,1.25]\)の実数

であり、出力はそれらに対応する関数

  1. \(\frac{1}{1-x}\)

  2. \(e^x\)

をもとめる。

Hide code cell source
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.collections
import matplotlib.animation
import matplotlib.colors
import math
from IPython.display import HTML

4.1.1. 湿度との回帰#

4.2. データの入手方法・構築方法#

今回のデータは、それぞれ以下のように作成した。

4.2.1. \(\frac{1}{1-x}\)について#

こちらの学習データは、\(n\in [0, 90]\)における\(\left(n, \frac{1}{1- \frac{n}{100}} \right)\)によって作成した。

一方評価データについては\(\left(n+0.5, \frac{1}{1- \frac{n+0.5}{100}} \right)\)によって作成した。

今回、\(n\)\([0,89]\)としているのは、\(n\)が100に近づくと\(1- \frac{n}{100}\)が0に近づき、\(\frac{1}{1- \frac{n}{100}}\)が非常に大きくなってしまうため、この範囲に設定した。

for i in range(90):
  print("[", i / 100,",", 1/ (1 - i/100) ,"]", end = ",")
[ 0.0 , 1.0 ],[ 0.01 , 1.0101010101010102 ],[ 0.02 , 1.0204081632653061 ],[ 0.03 , 1.0309278350515465 ],[ 0.04 , 1.0416666666666667 ],[ 0.05 , 1.0526315789473684 ],[ 0.06 , 1.0638297872340425 ],[ 0.07 , 1.0752688172043012 ],[ 0.08 , 1.0869565217391304 ],[ 0.09 , 1.0989010989010988 ],[ 0.1 , 1.1111111111111112 ],[ 0.11 , 1.1235955056179776 ],[ 0.12 , 1.1363636363636365 ],[ 0.13 , 1.1494252873563218 ],[ 0.14 , 1.1627906976744187 ],[ 0.15 , 1.1764705882352942 ],[ 0.16 , 1.1904761904761905 ],[ 0.17 , 1.2048192771084338 ],[ 0.18 , 1.2195121951219512 ],[ 0.19 , 1.2345679012345678 ],[ 0.2 , 1.25 ],[ 0.21 , 1.2658227848101264 ],[ 0.22 , 1.282051282051282 ],[ 0.23 , 1.2987012987012987 ],[ 0.24 , 1.3157894736842106 ],[ 0.25 , 1.3333333333333333 ],[ 0.26 , 1.3513513513513513 ],[ 0.27 , 1.36986301369863 ],[ 0.28 , 1.3888888888888888 ],[ 0.29 , 1.4084507042253522 ],[ 0.3 , 1.4285714285714286 ],[ 0.31 , 1.4492753623188408 ],[ 0.32 , 1.4705882352941178 ],[ 0.33 , 1.492537313432836 ],[ 0.34 , 1.5151515151515154 ],[ 0.35 , 1.5384615384615383 ],[ 0.36 , 1.5625 ],[ 0.37 , 1.5873015873015872 ],[ 0.38 , 1.6129032258064517 ],[ 0.39 , 1.639344262295082 ],[ 0.4 , 1.6666666666666667 ],[ 0.41 , 1.6949152542372878 ],[ 0.42 , 1.7241379310344827 ],[ 0.43 , 1.7543859649122806 ],[ 0.44 , 1.7857142857142856 ],[ 0.45 , 1.8181818181818181 ],[ 0.46 , 1.8518518518518516 ],[ 0.47 , 1.8867924528301885 ],[ 0.48 , 1.923076923076923 ],[ 0.49 , 1.9607843137254901 ],[ 0.5 , 2.0 ],[ 0.51 , 2.0408163265306123 ],[ 0.52 , 2.0833333333333335 ],[ 0.53 , 2.127659574468085 ],[ 0.54 , 2.173913043478261 ],[ 0.55 , 2.2222222222222223 ],[ 0.56 , 2.272727272727273 ],[ 0.57 , 2.325581395348837 ],[ 0.58 , 2.380952380952381 ],[ 0.59 , 2.4390243902439024 ],[ 0.6 , 2.5 ],[ 0.61 , 2.564102564102564 ],[ 0.62 , 2.6315789473684212 ],[ 0.63 , 2.7027027027027026 ],[ 0.64 , 2.7777777777777777 ],[ 0.65 , 2.857142857142857 ],[ 0.66 , 2.9411764705882355 ],[ 0.67 , 3.0303030303030307 ],[ 0.68 , 3.1250000000000004 ],[ 0.69 , 3.2258064516129026 ],[ 0.7 , 3.333333333333333 ],[ 0.71 , 3.4482758620689653 ],[ 0.72 , 3.571428571428571 ],[ 0.73 , 3.7037037037037033 ],[ 0.74 , 3.846153846153846 ],[ 0.75 , 4.0 ],[ 0.76 , 4.166666666666667 ],[ 0.77 , 4.347826086956522 ],[ 0.78 , 4.545454545454546 ],[ 0.79 , 4.761904761904763 ],[ 0.8 , 5.000000000000001 ],[ 0.81 , 5.263157894736843 ],[ 0.82 , 5.5555555555555545 ],[ 0.83 , 5.882352941176469 ],[ 0.84 , 6.249999999999999 ],[ 0.85 , 6.666666666666666 ],[ 0.86 , 7.142857142857142 ],[ 0.87 , 7.692307692307692 ],[ 0.88 , 8.333333333333334 ],[ 0.89 , 9.090909090909092 ],
for i in range(90):
  print("[", (i + 0.5) / 100,",", 1/ (1 - (i + 0.5)/100) ,"]", end = ",")
[ 0.005 , 1.0050251256281406 ],[ 0.015 , 1.015228426395939 ],[ 0.025 , 1.0256410256410258 ],[ 0.035 , 1.0362694300518136 ],[ 0.045 , 1.0471204188481675 ],[ 0.055 , 1.0582010582010584 ],[ 0.065 , 1.06951871657754 ],[ 0.075 , 1.081081081081081 ],[ 0.085 , 1.0928961748633879 ],[ 0.095 , 1.1049723756906078 ],[ 0.105 , 1.1173184357541899 ],[ 0.115 , 1.1299435028248588 ],[ 0.125 , 1.1428571428571428 ],[ 0.135 , 1.1560693641618498 ],[ 0.145 , 1.1695906432748537 ],[ 0.155 , 1.183431952662722 ],[ 0.165 , 1.1976047904191618 ],[ 0.175 , 1.2121212121212122 ],[ 0.185 , 1.2269938650306749 ],[ 0.195 , 1.2422360248447206 ],[ 0.205 , 1.2578616352201257 ],[ 0.215 , 1.2738853503184713 ],[ 0.225 , 1.2903225806451613 ],[ 0.235 , 1.3071895424836601 ],[ 0.245 , 1.3245033112582782 ],[ 0.255 , 1.342281879194631 ],[ 0.265 , 1.3605442176870748 ],[ 0.275 , 1.3793103448275863 ],[ 0.285 , 1.3986013986013985 ],[ 0.295 , 1.4184397163120566 ],[ 0.305 , 1.4388489208633093 ],[ 0.315 , 1.4598540145985401 ],[ 0.325 , 1.4814814814814814 ],[ 0.335 , 1.5037593984962405 ],[ 0.345 , 1.5267175572519083 ],[ 0.355 , 1.5503875968992247 ],[ 0.365 , 1.574803149606299 ],[ 0.375 , 1.6 ],[ 0.385 , 1.6260162601626016 ],[ 0.395 , 1.6528925619834711 ],[ 0.405 , 1.680672268907563 ],[ 0.415 , 1.7094017094017095 ],[ 0.425 , 1.7391304347826089 ],[ 0.435 , 1.7699115044247788 ],[ 0.445 , 1.801801801801802 ],[ 0.455 , 1.8348623853211012 ],[ 0.465 , 1.869158878504673 ],[ 0.475 , 1.9047619047619047 ],[ 0.485 , 1.941747572815534 ],[ 0.495 , 1.9801980198019802 ],[ 0.505 , 2.0202020202020203 ],[ 0.515 , 2.061855670103093 ],[ 0.525 , 2.1052631578947367 ],[ 0.535 , 2.1505376344086025 ],[ 0.545 , 2.197802197802198 ],[ 0.555 , 2.247191011235955 ],[ 0.565 , 2.2988505747126435 ],[ 0.575 , 2.352941176470588 ],[ 0.585 , 2.4096385542168672 ],[ 0.595 , 2.4691358024691357 ],[ 0.605 , 2.531645569620253 ],[ 0.615 , 2.5974025974025974 ],[ 0.625 , 2.6666666666666665 ],[ 0.635 , 2.73972602739726 ],[ 0.645 , 2.8169014084507045 ],[ 0.655 , 2.8985507246376816 ],[ 0.665 , 2.985074626865672 ],[ 0.675 , 3.0769230769230775 ],[ 0.685 , 3.1746031746031753 ],[ 0.695 , 3.2786885245901636 ],[ 0.705 , 3.3898305084745757 ],[ 0.715 , 3.508771929824561 ],[ 0.725 , 3.6363636363636362 ],[ 0.735 , 3.773584905660377 ],[ 0.745 , 3.9215686274509802 ],[ 0.755 , 4.081632653061225 ],[ 0.765 , 4.25531914893617 ],[ 0.775 , 4.444444444444445 ],[ 0.785 , 4.651162790697675 ],[ 0.795 , 4.878048780487806 ],[ 0.805 , 5.1282051282051295 ],[ 0.815 , 5.4054054054054035 ],[ 0.825 , 5.714285714285713 ],[ 0.835 , 6.06060606060606 ],[ 0.845 , 6.451612903225805 ],[ 0.855 , 6.896551724137931 ],[ 0.865 , 7.4074074074074066 ],[ 0.875 , 8.0 ],[ 0.885 , 8.695652173913045 ],[ 0.895 , 9.523809523809526 ],
D = np.array([[ 0.0 , 1.0 ],[ 0.01 , 1.0101010101010102 ],[ 0.02 , 1.0204081632653061 ],[ 0.03 , 1.0309278350515465 ],[ 0.04 , 1.0416666666666667 ],[ 0.05 , 1.0526315789473684 ],[ 0.06 , 1.0638297872340425 ],[ 0.07 , 1.0752688172043012 ],[ 0.08 , 1.0869565217391304 ],[ 0.09 , 1.0989010989010988 ],[ 0.1 , 1.1111111111111112 ],[ 0.11 , 1.1235955056179776 ],[ 0.12 , 1.1363636363636365 ],[ 0.13 , 1.1494252873563218 ],[ 0.14 , 1.1627906976744187 ],[ 0.15 , 1.1764705882352942 ],[ 0.16 , 1.1904761904761905 ],[ 0.17 , 1.2048192771084338 ],[ 0.18 , 1.2195121951219512 ],[ 0.19 , 1.2345679012345678 ],[ 0.2 , 1.25 ],[ 0.21 , 1.2658227848101264 ],[ 0.22 , 1.282051282051282 ],[ 0.23 , 1.2987012987012987 ],[ 0.24 , 1.3157894736842106 ],[ 0.25 , 1.3333333333333333 ],[ 0.26 , 1.3513513513513513 ],[ 0.27 , 1.36986301369863 ],[ 0.28 , 1.3888888888888888 ],[ 0.29 , 1.4084507042253522 ],[ 0.3 , 1.4285714285714286 ],[ 0.31 , 1.4492753623188408 ],[ 0.32 , 1.4705882352941178 ],[ 0.33 , 1.492537313432836 ],[ 0.34 , 1.5151515151515154 ],[ 0.35 , 1.5384615384615383 ],[ 0.36 , 1.5625 ],[ 0.37 , 1.5873015873015872 ],[ 0.38 , 1.6129032258064517 ],[ 0.39 , 1.639344262295082 ],[ 0.4 , 1.6666666666666667 ],[ 0.41 , 1.6949152542372878 ],[ 0.42 , 1.7241379310344827 ],[ 0.43 , 1.7543859649122806 ],[ 0.44 , 1.7857142857142856 ],[ 0.45 , 1.8181818181818181 ],[ 0.46 , 1.8518518518518516 ],[ 0.47 , 1.8867924528301885 ],[ 0.48 , 1.923076923076923 ],[ 0.49 , 1.9607843137254901 ],[ 0.5 , 2.0 ],[ 0.51 , 2.0408163265306123 ],[ 0.52 , 2.0833333333333335 ],[ 0.53 , 2.127659574468085 ],[ 0.54 , 2.173913043478261 ],[ 0.55 , 2.2222222222222223 ],[ 0.56 , 2.272727272727273 ],[ 0.57 , 2.325581395348837 ],[ 0.58 , 2.380952380952381 ],[ 0.59 , 2.4390243902439024 ],[ 0.6 , 2.5 ],[ 0.61 , 2.564102564102564 ],[ 0.62 , 2.6315789473684212 ],[ 0.63 , 2.7027027027027026 ],[ 0.64 , 2.7777777777777777 ],[ 0.65 , 2.857142857142857 ],[ 0.66 , 2.9411764705882355 ],[ 0.67 , 3.0303030303030307 ],[ 0.68 , 3.1250000000000004 ],[ 0.69 , 3.2258064516129026 ],[ 0.7 , 3.333333333333333 ],[ 0.71 , 3.4482758620689653 ],[ 0.72 , 3.571428571428571 ],[ 0.73 , 3.7037037037037033 ],[ 0.74 , 3.846153846153846 ],[ 0.75 , 4.0 ],[ 0.76 , 4.166666666666667 ],[ 0.77 , 4.347826086956522 ],[ 0.78 , 4.545454545454546 ],[ 0.79 , 4.761904761904763 ],[ 0.8 , 5.000000000000001 ],[ 0.81 , 5.263157894736843 ],[ 0.82 , 5.5555555555555545 ],[ 0.83 , 5.882352941176469 ],[ 0.84 , 6.249999999999999 ],[ 0.85 , 6.666666666666666 ],[ 0.86 , 7.142857142857142 ],[ 0.87 , 7.692307692307692 ],[ 0.88 , 8.333333333333334 ],[ 0.89 , 9.090909090909092 ]])
D_t = np.array([[ 0.005 , 1.0050251256281406 ],[ 0.015 , 1.015228426395939 ],[ 0.025 , 1.0256410256410258 ],[ 0.035 , 1.0362694300518136 ],[ 0.045 , 1.0471204188481675 ],[ 0.055 , 1.0582010582010584 ],[ 0.065 , 1.06951871657754 ],[ 0.075 , 1.081081081081081 ],[ 0.085 , 1.0928961748633879 ],[ 0.095 , 1.1049723756906078 ],[ 0.105 , 1.1173184357541899 ],[ 0.115 , 1.1299435028248588 ],[ 0.125 , 1.1428571428571428 ],[ 0.135 , 1.1560693641618498 ],[ 0.145 , 1.1695906432748537 ],[ 0.155 , 1.183431952662722 ],[ 0.165 , 1.1976047904191618 ],[ 0.175 , 1.2121212121212122 ],[ 0.185 , 1.2269938650306749 ],[ 0.195 , 1.2422360248447206 ],[ 0.205 , 1.2578616352201257 ],[ 0.215 , 1.2738853503184713 ],[ 0.225 , 1.2903225806451613 ],[ 0.235 , 1.3071895424836601 ],[ 0.245 , 1.3245033112582782 ],[ 0.255 , 1.342281879194631 ],[ 0.265 , 1.3605442176870748 ],[ 0.275 , 1.3793103448275863 ],[ 0.285 , 1.3986013986013985 ],[ 0.295 , 1.4184397163120566 ],[ 0.305 , 1.4388489208633093 ],[ 0.315 , 1.4598540145985401 ],[ 0.325 , 1.4814814814814814 ],[ 0.335 , 1.5037593984962405 ],[ 0.345 , 1.5267175572519083 ],[ 0.355 , 1.5503875968992247 ],[ 0.365 , 1.574803149606299 ],[ 0.375 , 1.6 ],[ 0.385 , 1.6260162601626016 ],[ 0.395 , 1.6528925619834711 ],[ 0.405 , 1.680672268907563 ],[ 0.415 , 1.7094017094017095 ],[ 0.425 , 1.7391304347826089 ],[ 0.435 , 1.7699115044247788 ],[ 0.445 , 1.801801801801802 ],[ 0.455 , 1.8348623853211012 ],[ 0.465 , 1.869158878504673 ],[ 0.475 , 1.9047619047619047 ],[ 0.485 , 1.941747572815534 ],[ 0.495 , 1.9801980198019802 ],[ 0.505 , 2.0202020202020203 ],[ 0.515 , 2.061855670103093 ],[ 0.525 , 2.1052631578947367 ],[ 0.535 , 2.1505376344086025 ],[ 0.545 , 2.197802197802198 ],[ 0.555 , 2.247191011235955 ],[ 0.565 , 2.2988505747126435 ],[ 0.575 , 2.352941176470588 ],[ 0.585 , 2.4096385542168672 ],[ 0.595 , 2.4691358024691357 ],[ 0.605 , 2.531645569620253 ],[ 0.615 , 2.5974025974025974 ],[ 0.625 , 2.6666666666666665 ],[ 0.635 , 2.73972602739726 ],[ 0.645 , 2.8169014084507045 ],[ 0.655 , 2.8985507246376816 ],[ 0.665 , 2.985074626865672 ],[ 0.675 , 3.0769230769230775 ],[ 0.685 , 3.1746031746031753 ],[ 0.695 , 3.2786885245901636 ],[ 0.705 , 3.3898305084745757 ],[ 0.715 , 3.508771929824561 ],[ 0.725 , 3.6363636363636362 ],[ 0.735 , 3.773584905660377 ],[ 0.745 , 3.9215686274509802 ],[ 0.755 , 4.081632653061225 ],[ 0.765 , 4.25531914893617 ],[ 0.775 , 4.444444444444445 ],[ 0.785 , 4.651162790697675 ],[ 0.795 , 4.878048780487806 ],[ 0.805 , 5.1282051282051295 ],[ 0.815 , 5.4054054054054035 ],[ 0.825 , 5.714285714285713 ],[ 0.835 , 6.06060606060606 ],[ 0.845 , 6.451612903225805 ],[ 0.855 , 6.896551724137931 ],[ 0.865 , 7.4074074074074066 ],[ 0.875 , 8.0 ],[ 0.885 , 8.695652173913045 ],[ 0.895 , 9.523809523809526 ]])

4.2.2. \(e^x\)について#

こちらの学習データは、\(n\in [0, 100]\)における\((n,\exp{(n/80)})\)によって作成した。

一方評価データについては\(\left(n + 0.5,\exp{\left(\frac{n + 0.5}{80}\right)}\right)\)によって作成した。

for i in range(100):
  print("[", i / 80,",", math.e ** (i / 80) ,"]", end = ",")
[ 0.0 , 1.0 ],[ 0.0125 , 1.0125784515406344 ],[ 0.025 , 1.0253151205244289 ],[ 0.0375 , 1.038211997081825 ],[ 0.05 , 1.0512710963760241 ],[ 0.0625 , 1.0644944589178593 ],[ 0.075 , 1.0778841508846315 ],[ 0.0875 , 1.0914422644429518 ],[ 0.1 , 1.1051709180756477 ],[ 0.1125 , 1.1190722569127804 ],[ 0.125 , 1.1331484530668263 ],[ 0.1375 , 1.1474017059720723 ],[ 0.15 , 1.161834242728283 ],[ 0.1625 , 1.1764483184486905 ],[ 0.175 , 1.191246216612358 ],[ 0.1875 , 1.2062302494209807 ],[ 0.2 , 1.2214027581601699 ],[ 0.2125 , 1.2367661135652848 ],[ 0.225 , 1.2523227161918644 ],[ 0.2375 , 1.2680749967907192 ],[ 0.25 , 1.2840254166877414 ],[ 0.2625 , 1.300176468168491 ],[ 0.275 , 1.3165306748676215 ],[ 0.2875 , 1.3330905921632026 ],[ 0.3 , 1.349858807576003 ],[ 0.3125 , 1.3668379411737963 ],[ 0.325 , 1.3840306459807514 ],[ 0.3375 , 1.4014396083919731 ],[ 0.35 , 1.4190675485932571 ],[ 0.3625 , 1.4369172209861243 ],[ 0.375 , 1.4549914146182013 ],[ 0.3875 , 1.4732929536190154 ],[ 0.4 , 1.4918246976412703 ],[ 0.4125 , 1.5105895423076725 ],[ 0.425 , 1.5295904196633787 ],[ 0.4375 , 1.5488302986341331 ],[ 0.45 , 1.5683121854901687 ],[ 0.4625 , 1.5880391243159433 ],[ 0.475 , 1.6080141974857827 ],[ 0.4875 , 1.6282405261455097 ],[ 0.5 , 1.6487212707001282 ],[ 0.5125 , 1.6694596313076426 ],[ 0.525 , 1.6904588483790914 ],[ 0.5375 , 1.7117222030848642 ],[ 0.55 , 1.7332530178673953 ],[ 0.5625 , 1.7550546569602985 ],[ 0.575 , 1.7771305269140383 ],[ 0.5875 , 1.7994840771282086 ],[ 0.6 , 1.8221188003905089 ],[ 0.6125 , 1.8450382334225 ],[ 0.625 , 1.8682459574322223 ],[ 0.6375 , 1.8917455986737695 ],[ 0.65 , 1.915540829013896 ],[ 0.6625 , 1.9396353665057537 ],[ 0.675 , 1.9640329759698472 ],[ 0.6875 , 1.9887374695822917 ],[ 0.7 , 2.013752707470476 ],[ 0.7125 , 2.0390825983162153 ],[ 0.725 , 2.0647310999664863 ],[ 0.7375 , 2.0907022200518557 ],[ 0.75 , 2.117000016612675 ],[ 0.7625 , 2.143628598733159 ],[ 0.775 , 2.1705921271834425 ],[ 0.7875 , 2.1978948150697017 ],[ 0.8 , 2.2255409284924674 ],[ 0.8125 , 2.2535347872132085 ],[ 0.825 , 2.2818807653293036 ],[ 0.8375 , 2.310583291957504 ],[ 0.85 , 2.3396468519259908 ],[ 0.8625 , 2.36907598647514 ],[ 0.875 , 2.3988752939670976 ],[ 0.8875 , 2.429049430604288 ],[ 0.9 , 2.4596031111569494 ],[ 0.9125 , 2.490541109699831 ],[ 0.925 , 2.521868260358148 ],[ 0.9375 , 2.553589458062927 ],[ 0.95 , 2.585709659315846 ],[ 0.9625 , 2.618233882963701 ],[ 0.975 , 2.6511672109826065 ],[ 0.9875 , 2.68451478927207 ],[ 1.0 , 2.718281828459045 ],[ 1.0125 , 2.752473604712104 ],[ 1.025 , 2.7870954605658502 ],[ 1.0375 , 2.8221528057557004 ],[ 1.05 , 2.857651118063164 ],[ 1.0625 , 2.8935959441717607 ],[ 1.075 , 2.9299929005337013 ],[ 1.0875 , 2.966847674247467 ],[ 1.1 , 3.0041660239464334 ],[ 1.1125 , 3.0419537806986634 ],[ 1.125 , 3.080216848918031 ],[ 1.1375 , 3.118961207286792 ],[ 1.15 , 3.158192909689767 ],[ 1.1625 , 3.1979180861602754 ],[ 1.175 , 3.2381429438379605 ],[ 1.1875 , 3.2788737679386735 ],[ 1.2 , 3.3201169227365472 ],[ 1.2125 , 3.3618788525584287 ],[ 1.225 , 3.404166082790819 ],[ 1.2375 , 3.4469852208994745 ],
for i in range(100):
  print("[", (i + 0.5) / 80,",", math.e ** ((i + 0.5) / 80) ,"]", end = ",")
[ 0.00625 , 1.006269572003762 ],[ 0.01875 , 1.0189268850520263 ],[ 0.03125 , 1.0317434074991028 ],[ 0.04375 , 1.0447211419526992 ],[ 0.05625 , 1.0578621162102273 ],[ 0.06875 , 1.0711683835756507 ],[ 0.08125 , 1.0846420231803167 ],[ 0.09375 , 1.0982851403078258 ],[ 0.10625 , 1.1120998667229867 ],[ 0.11875 , 1.1260883610049077 ],[ 0.13125 , 1.1402528088842803 ],[ 0.14375 , 1.1545954235849034 ],[ 0.15625 , 1.1691184461695043 ],[ 0.16875 , 1.1838241458899093 ],[ 0.18125 , 1.1987148205416183 ],[ 0.19375 , 1.2137927968228412 ],[ 0.20625 , 1.2290604306980486 ],[ 0.21875 , 1.2445201077660952 ],[ 0.23125 , 1.2601742436329761 ],[ 0.24375 , 1.276025284289269 ],[ 0.25625 , 1.2920757064923258 ],[ 0.26875 , 1.3083280181532704 ],[ 0.28125 , 1.3247847587288655 ],[ 0.29375 , 1.3414484996183076 ],[ 0.30625 , 1.3583218445650131 ],[ 0.31875 , 1.3754074300634593 ],[ 0.33125 , 1.392707925771141 ],[ 0.34375 , 1.4102260349257107 ],[ 0.35625 , 1.4279644947673646 ],[ 0.36875 , 1.4459260769665425 ],[ 0.38125 , 1.4641135880570055 ],[ 0.39375 , 1.482529869874365 ],[ 0.40625 , 1.5011778000001228 ],[ 0.41875 , 1.5200602922113005 ],[ 0.43125 , 1.539180296935723 ],[ 0.44375 , 1.558540801713028 ],[ 0.45625 , 1.5781448316614768 ],[ 0.46875 , 1.5979954499506333 ],[ 0.48125 , 1.6180957582799915 ],[ 0.49375 , 1.6384488973636224 ],[ 0.50625 , 1.6590580474209164 ],[ 0.51875 , 1.6799264286735 ],[ 0.53125 , 1.7010573018484005 ],[ 0.54375 , 1.7224539686875429 ],[ 0.55625 , 1.7441197724636526 ],[ 0.56875 , 1.7660580985026488 ],[ 0.58125 , 1.7882723747126095 ],[ 0.59375 , 1.810766072119387 ],[ 0.60625 , 1.8335427054089657 ],[ 0.61875 , 1.856605833476636 ],[ 0.63125 , 1.8799590599830809 ],[ 0.64375 , 1.9036060339174548 ],[ 0.65625 , 1.9275504501675447 ],[ 0.66875 , 1.951796050097105 ],[ 0.68125 , 1.976346622130453 ],[ 0.69375 , 2.0012060023444174 ],[ 0.70625 , 2.0263780750677336 ],[ 0.71875 , 2.0518667734879767 ],[ 0.73125 , 2.077676080266133 ],[ 0.74375 , 2.103810028158896 ],[ 0.75625 , 2.130272700648793 ],[ 0.76875 , 2.1570682325822403 ],[ 0.78125 , 2.184200810815618 ],[ 0.79375 , 2.211674674869476 ],[ 0.80625 , 2.2394941175909704 ],[ 0.81875 , 2.2676634858246243 ],[ 0.83125 , 2.2961871810915353 ],[ 0.84375 , 2.325069660277121 ],[ 0.85625 , 2.354315436327516 ],[ 0.86875 , 2.383929078954729 ],[ 0.88125 , 2.4139152153506704 ],[ 0.89375 , 2.4442785309101587 ],[ 0.90625 , 2.475023769963025 ],[ 0.91875 , 2.506155736515423 ],[ 0.93125 , 2.537679295000465 ],[ 0.94375 , 2.5695993710383 ],[ 0.95625 , 2.60192095220575 ],[ 0.96875 , 2.634649088815631 ],[ 0.98125 , 2.667788894705875 ],[ 0.99375 , 2.7013455480385753 ],[ 1.00625 , 2.735324292109087 ],[ 1.01875 , 2.7697304361653012 ],[ 1.03125 , 2.8045693562372263 ],[ 1.04375 , 2.8398464959770044 ],[ 1.05625 , 2.8755673675094915 ],[ 1.06875 , 2.91173755229354 ],[ 1.08125 , 2.948362701994109 ],[ 1.09375 , 2.985448539365356 ],[ 1.10625 , 3.0230008591448203 ],[ 1.11875 , 3.0610255289588695 ],[ 1.13125 , 3.099528490239524 ],[ 1.14375 , 3.138515759152817 ],[ 1.15625 , 3.177993427538838 ],[ 1.16875 , 3.2179676638635897 ],[ 1.18125 , 3.258444714182826 ],[ 1.19375 , 3.2994309031180116 ],[ 1.20625 , 3.340932634844553 ],[ 1.21875 , 3.382956394092469 ],[ 1.23125 , 3.42550874715964 ],[ 1.24375 , 3.468596342937807 ],
D2 = np.array([[ 0.0 , 1.0 ],[ 0.0125 , 1.0125784515406344 ],[ 0.025 , 1.0253151205244289 ],[ 0.0375 , 1.038211997081825 ],[ 0.05 , 1.0512710963760241],[ 0.0625 , 1.0644944589178593 ],[ 0.075 , 1.0778841508846315 ],[ 0.0875 , 1.0914422644429518 ],[ 0.1 , 1.1051709180756477 ],[ 0.1125 , 1.1190722569127804 ],[ 0.125 , 1.1331484530668263 ],[ 0.1375 , 1.1474017059720723 ],[ 0.15 , 1.161834242728283 ],[ 0.1625 , 1.1764483184486905 ],[ 0.175 , 1.191246216612358 ],[ 0.1875 , 1.2062302494209807 ],[ 0.2 , 1.2214027581601699 ],[ 0.2125 , 1.2367661135652848 ],[ 0.225 , 1.2523227161918644 ],[ 0.2375 , 1.2680749967907192 ],[ 0.25 , 1.2840254166877414 ],[ 0.2625 , 1.300176468168491 ],[ 0.275 , 1.3165306748676215 ],[ 0.2875 , 1.3330905921632026 ],[ 0.3 , 1.349858807576003 ],[ 0.3125 , 1.3668379411737963 ],[ 0.325 , 1.3840306459807514 ],[ 0.3375 , 1.4014396083919731 ],[ 0.35 , 1.4190675485932571 ],[ 0.3625 , 1.4369172209861243 ],[ 0.375 , 1.4549914146182013 ],[ 0.3875 , 1.4732929536190154 ],[ 0.4 , 1.4918246976412703 ],[ 0.4125 , 1.5105895423076725 ],[ 0.425 , 1.5295904196633787 ],[ 0.4375 , 1.5488302986341331 ],[ 0.45 , 1.5683121854901687 ],[ 0.4625 , 1.5880391243159433 ],[ 0.475 , 1.6080141974857827 ],[ 0.4875 , 1.6282405261455097 ],[ 0.5 , 1.6487212707001282 ],[ 0.5125 , 1.6694596313076426 ],[ 0.525 , 1.6904588483790914 ],[ 0.5375 , 1.7117222030848642 ],[ 0.55 , 1.7332530178673953 ],[ 0.5625 , 1.7550546569602985 ],[ 0.575 , 1.7771305269140383 ],[ 0.5875 , 1.7994840771282086 ],[ 0.6 , 1.8221188003905089 ],[ 0.6125 , 1.8450382334225 ],[ 0.625 , 1.8682459574322223 ],[ 0.6375 , 1.8917455986737695 ],[ 0.65 , 1.915540829013896 ],[ 0.6625 , 1.9396353665057537 ],[ 0.675 , 1.9640329759698472 ],[ 0.6875 , 1.9887374695822917 ],[ 0.7 , 2.013752707470476 ],[ 0.7125 , 2.0390825983162153 ],[ 0.725 , 2.0647310999664863 ],[ 0.7375 , 2.0907022200518557 ],[ 0.75 , 2.117000016612675 ],[ 0.7625 , 2.143628598733159 ],[ 0.775 , 2.1705921271834425 ],[ 0.7875 , 2.1978948150697017 ],[ 0.8 , 2.2255409284924674 ],[ 0.8125 , 2.2535347872132085 ],[ 0.825 , 2.2818807653293036 ],[ 0.8375 , 2.310583291957504 ],[ 0.85 , 2.3396468519259908 ],[ 0.8625 , 2.36907598647514 ],[ 0.875 , 2.3988752939670976 ],[ 0.8875 , 2.429049430604288 ],[ 0.9 , 2.4596031111569494 ],[ 0.9125 , 2.490541109699831 ],[ 0.925 , 2.521868260358148 ],[ 0.9375 , 2.553589458062927 ],[ 0.95 , 2.585709659315846 ],[ 0.9625 , 2.618233882963701 ],[ 0.975 , 2.6511672109826065 ],[ 0.9875 , 2.68451478927207 ],[ 1.0 , 2.718281828459045 ],[ 1.0125 , 2.752473604712104 ],[ 1.025 , 2.7870954605658502 ],[ 1.0375 , 2.8221528057557004 ],[ 1.05 , 2.857651118063164 ],[ 1.0625 , 2.8935959441717607 ],[ 1.075 , 2.9299929005337013 ],[ 1.0875 , 2.966847674247467 ],[ 1.1 , 3.0041660239464334 ],[ 1.1125 , 3.0419537806986634 ],[ 1.125 , 3.080216848918031 ],[ 1.1375 , 3.118961207286792 ],[ 1.15 , 3.158192909689767 ],[ 1.1625 , 3.1979180861602754 ],[ 1.175 , 3.2381429438379605 ],[ 1.1875 , 3.2788737679386735 ],[ 1.2 , 3.3201169227365472 ],[ 1.2125 , 3.3618788525584287 ],[ 1.225 , 3.404166082790819 ],[ 1.2375 , 3.4469852208994745 ]])
D2_t = np.array([[ 0.00625 , 1.006269572003762 ],[ 0.01875 , 1.0189268850520263 ],[ 0.03125 , 1.0317434074991028 ],[ 0.04375 , 1.0447211419526992 ],[ 0.05625 , 1.0578621162102273 ],[ 0.06875 , 1.0711683835756507 ],[ 0.08125 , 1.0846420231803167 ],[ 0.09375 , 1.0982851403078258 ],[ 0.10625 , 1.1120998667229867 ],[ 0.11875 , 1.1260883610049077 ],[ 0.13125 , 1.1402528088842803 ],[ 0.14375 , 1.1545954235849034 ],[ 0.15625 , 1.1691184461695043 ],[ 0.16875 , 1.1838241458899093 ],[ 0.18125 , 1.1987148205416183 ],[ 0.19375 , 1.2137927968228412 ],[ 0.20625 , 1.2290604306980486 ],[ 0.21875 , 1.2445201077660952 ],[ 0.23125 , 1.2601742436329761 ],[ 0.24375 , 1.276025284289269 ],[ 0.25625 , 1.2920757064923258 ],[ 0.26875 , 1.3083280181532704 ],[ 0.28125 , 1.3247847587288655 ],[ 0.29375 , 1.3414484996183076 ],[ 0.30625 , 1.3583218445650131 ],[ 0.31875 , 1.3754074300634593 ],[ 0.33125 , 1.392707925771141 ],[ 0.34375 , 1.4102260349257107 ],[ 0.35625 , 1.4279644947673646 ],[ 0.36875 , 1.4459260769665425 ],[ 0.38125 , 1.4641135880570055 ],[ 0.39375 , 1.482529869874365 ],[ 0.40625 , 1.5011778000001228 ],[ 0.41875 , 1.5200602922113005 ],[ 0.43125 , 1.539180296935723 ],[ 0.44375 , 1.558540801713028 ],[ 0.45625 , 1.5781448316614768 ],[ 0.46875 , 1.5979954499506333 ],[ 0.48125 , 1.6180957582799915 ],[ 0.49375 , 1.6384488973636224 ],[ 0.50625 , 1.6590580474209164 ],[ 0.51875 , 1.6799264286735 ],[ 0.53125 , 1.7010573018484005 ],[ 0.54375 , 1.7224539686875429 ],[ 0.55625 , 1.7441197724636526 ],[ 0.56875 , 1.7660580985026488 ],[ 0.58125 , 1.7882723747126095 ],[ 0.59375 , 1.810766072119387 ],[ 0.60625 , 1.8335427054089657 ],[ 0.61875 , 1.856605833476636 ],[ 0.63125 , 1.8799590599830809 ],[ 0.64375 , 1.9036060339174548 ],[ 0.65625 , 1.9275504501675447 ],[ 0.66875 , 1.951796050097105 ],[ 0.68125 , 1.976346622130453 ],[ 0.69375 , 2.0012060023444174 ],[ 0.70625 , 2.0263780750677336 ],[ 0.71875 , 2.0518667734879767 ],[ 0.73125 , 2.077676080266133 ],[ 0.74375 , 2.103810028158896 ],[ 0.75625 , 2.130272700648793 ],[ 0.76875 , 2.1570682325822403 ],[ 0.78125 , 2.184200810815618 ],[ 0.79375 , 2.211674674869476 ],[ 0.80625 , 2.2394941175909704 ],[ 0.81875 , 2.2676634858246243 ],[ 0.83125 , 2.2961871810915353 ],[ 0.84375 , 2.325069660277121 ],[ 0.85625 , 2.354315436327516 ],[ 0.86875 , 2.383929078954729 ],[ 0.88125 , 2.4139152153506704 ],[ 0.89375 , 2.4442785309101587 ],[ 0.90625 , 2.475023769963025 ],[ 0.91875 , 2.506155736515423 ],[ 0.93125 , 2.537679295000465 ],[ 0.94375 , 2.5695993710383 ],[ 0.95625 , 2.60192095220575 ],[ 0.96875 , 2.634649088815631 ],[ 0.98125 , 2.667788894705875 ],[ 0.99375 , 2.7013455480385753 ],[ 1.00625 , 2.735324292109087 ],[ 1.01875 , 2.7697304361653012 ],[ 1.03125 , 2.8045693562372263 ],[ 1.04375 , 2.8398464959770044 ],[ 1.05625 , 2.8755673675094915 ],[ 1.06875 , 2.91173755229354 ],[ 1.08125 , 2.948362701994109 ],[ 1.09375 , 2.985448539365356 ],[ 1.10625 , 3.0230008591448203 ],[ 1.11875 , 3.0610255289588695 ],[ 1.13125 , 3.099528490239524 ],[ 1.14375 , 3.138515759152817 ],[ 1.15625 , 3.177993427538838 ],[ 1.16875 , 3.2179676638635897 ],[ 1.18125 , 3.258444714182826 ],[ 1.19375 , 3.2994309031180116 ],[ 1.20625 , 3.340932634844553 ],[ 1.21875 , 3.382956394092469 ],[ 1.23125 , 3.42550874715964 ],[ 1.24375 , 3.468596342937807 ]])

4.3. 3. モデルの学習#

訓練データで回帰モデルを確率的勾配降下法により学習せよ。このとき、各エポック毎に以下の評価値を計算し、グラフとして表示せよ。

  • 訓練データ上の損失関数の値

  • 評価データ上の損失関数の値

訓練データ上の損失関数の値\(L_D\)に対して、評価データ上の損失関数の値は\(L_D'\)としてグラフ内に書き込んだ。

def draw_step(ax, eta, xt, yt, grad, w, X, X_test, y_test):
    def f(x):
      return w[0] + w[1] * x + w[2] * (x ** 2) + w[3] * (x ** 3) + w[4] * (x ** 4) + w[5] * (x ** 5) + w[6] * (x ** 6) + w[7] * (x ** 7) + w[8] * (x ** 8)

    artist = []
    x = np.arange(0, 3, 0.001)
    artist.extend(ax.plot(x, f(x), color='black'))
    artist.extend(ax.plot([xt], [yt], 'ro'))
    artist.append(ax.text(xt, yt, "$L_D = {}$".format(np.linalg.norm(y - np.dot(X,w), ord=2) ** 2), ha='right'))
    artist.append(ax.text(xt, yt + 0.5, "$L_D' = {}$".format(np.linalg.norm(y - np.dot(X_test,w), ord=2) ** 2), ha='right'))
    return artist

4.4. \(\frac{1}{1-x}\)の場合#

max_epochs = 10000
eta0 = 0.06
eps = 1e-5

X = np.vstack([np.ones_like(D[:,0]), D[:,0], D[:,0] ** 2, D[:,0] **3, D[:,0] ** 4, D[:,0] ** 5, D[:,0] ** 6, D[:,0] ** 7, D[:,0] ** 8]).T
X_test = np.vstack([np.ones_like(D_t[:,0]), D_t[:,0], D_t[:,0] ** 2, D_t[:,0] **3, D_t[:,0] ** 4, D_t[:,0] ** 5, D_t[:,0] ** 6, D_t[:,0] ** 7, D_t[:,0] ** 8]).T
y = D[:,1]
y_test = D_t[:,1]
w = np.zeros(X.shape[1])

fig, ax = plt.subplots(dpi=100, figsize=(7, 7))
ax.scatter(D[:,0], D[:,1], marker='o', color='b')
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.set_xlim(0, 1.1)
ax.set_ylim(0, 10)
ax.set_aspect('auto')
ax.grid()

artists = []
for t in range(max_epochs):
    eta = eta0 / np.sqrt(1+t)
    i = np.random.randint(0, X.shape[0])
    y_hat = np.dot(X[i], w)
    grad = 2 * (y_hat - y[i]) * X[i]
    if np.sum(np.abs(grad)) < eps:
        artists.append(draw_step(ax, eta, x_t, y_hat, grad, w, X, X_test, y_test))
        break
    w -= eta * grad
    x_t = X[i, 1]
    if t % 100 == 0:
      artists.append(draw_step(ax, eta, x_t, y_hat, grad, w, X,X_test, y_test))

ani = matplotlib.animation.ArtistAnimation(fig, artists, interval=100)
html = ani.to_jshtml()
plt.close(fig)
HTML(html)
w
array([0.75156354, 1.36198423, 1.5268169 , 1.49981302, 1.39535518,
       1.26342952, 1.12692918, 0.99633705, 0.87614808])

4.5. \(e^x\)について#

max_epochs = 10000
eta0 = 0.06
eps = 1e-5

X = np.vstack([np.ones_like(D2[:,0]), D2[:,0], D2[:,0] ** 2, D2[:,0] **3, D2[:,0] ** 4, D2[:,0] ** 5, D2[:,0] ** 6, D2[:,0] ** 7, D2[:,0] ** 8]).T
X_test = np.vstack([np.ones_like(D2_t[:,0]), D2_t[:,0], D2_t[:,0] ** 2, D2_t[:,0] **3, D2_t[:,0] ** 4, D2_t[:,0] ** 5, D2_t[:,0] ** 6, D2_t[:,0] ** 7, D2_t[:,0] ** 8]).T
y = D2[:,1]
y_test = D2_t[:,1]
w = np.zeros(X.shape[1])

fig, ax = plt.subplots(dpi=100, figsize=(8, 7))
ax.scatter(D2[:,0], D2[:,1], marker='o', color='b')
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.set_xlim(0, 2)
ax.set_ylim(0, 6)
ax.set_aspect('auto')
ax.grid()

artists = []
for t in range(max_epochs):
    eta = eta0 / np.sqrt(1+t)
    i = np.random.randint(0, X.shape[0])
    y_hat = np.dot(X[i], w)
    grad = 2 * (y_hat - y[i]) * X[i]
    if np.sum(np.abs(grad)) < eps:
        artists.append(draw_step(ax, eta, x_t, y_hat, grad, w, X, X_test, y_test))
        break
    w -= eta * grad
    x_t = X[i, 1]
    if t % 100 == 0:
      artists.append(draw_step(ax, eta, x_t, y_hat, grad, w, X,X_test, y_test))

ani = matplotlib.animation.ArtistAnimation(fig, artists, interval=100)
html = ani.to_jshtml()
plt.close(fig)
HTML(html)
w
array([ 1.08594289,  0.7140555 ,  0.45896046,  0.30221505,  0.19382896,
        0.1089877 ,  0.03465632, -0.03689101, -0.11089452])

4.6. 4. 回帰分析から得られた知見#

回帰分析から得られた知見をまとめよ。また、回帰モデルがうまく学習できなかった場合は、その原因を分析・考察せよ。

4.6.1. \(\frac{1}{1-x}\)について#

このケースでは、\(\boldsymbol{w} = {\rm ^T}(0.75156354, 1.36198423, 1.5268169 , 1.49981302, 1.39535518, 1.26342952, 1.12692918, 0.99633705, 0.87614808)\) となった。

予測される結果は\(\boldsymbol{w} = {\rm ^T}(1,1,1,1,1,1,1,1,1)\)である。

予想と実際の値を比較すると、それなりに近い値が出ている。したがって、回帰モデルはうまく学習できている。

一方、最終的な損失関数の値は\(L_D=12.221 ,L_D'=12.216\)となった。これは小さい値とは言い難い。 これは近似の精度があまり良くなかったことを意味する。

4.6.2. \(e^x\)について#

このケースでは、\(\boldsymbol{w} = {\rm ^T}(1.08594289, 0.7140555 , 0.45896046, 0.30221505, 0.19382896, 0.1089877 , 0.03465632, -0.03689101, -0.11089452)\) となった。

予測される結果は\(\boldsymbol{w} = {\rm ^T}(1,1,0.5,0.1667,0.0417,0.008333,0.001389,0.000198,2.480\times 10^{-5})\)である。

予想と実際の値を比較すると、値は近しいとは言えない。実際、グラフを見ても、\(x>1.35\)では、明らかに回帰曲線が減少している。これは\(e^x\)が単調増加であることに反する。

一方、最終的な損失関数の値は\(L_D=0.142 ,L_D'=0.155\)となった。こちらは、\(\frac{1}{1-x}\)の場合よりも圧倒的に小さい。

以上より、この場合では、過学習を起こしていると考えられる。

対策として、もっと大きな値を用いて学習をさせることが考えられるが、そうすると、掛け算をする回数が多くなり、オーバーフローする可能性が高くなってしまう。

for i in range(9):
  print(1/math.factorial(i),end = ",")
1.0,1.0,0.5,0.16666666666666666,0.041666666666666664,0.008333333333333333,0.001388888888888889,0.0001984126984126984,2.48015873015873e-05,

4.6.3. そのほかの回帰#

今回の課題に取り組むにあたり、具体的な事例の回帰を試みた。

  • 梅干しと気温及び湿度との関係

この関係について、e-Statと、気象庁のデータを用いて、実際に求めようとした。

データはCSV形式でダウンロードの上、一つのデータにした後、今回の実装で使いやすいように、ベクトルの形式に書き直すことによって、作成した。

import pandas as pd
df_1 = pd.read_csv('data.csv', sep=',')
df_2 = pd.read_csv('data_ume.csv', sep=',')
df_comp = pd.concat([df_1,df_2],axis='columns')
df_kenshou = pd.read_csv('data_kenshou.csv', sep=',')
df_ume_kenshou = pd.read_csv('data_ume_kenshou.csv', sep=',')
df_kenshou_comp = pd.concat([df_kenshou, df_ume_kenshou],axis='columns')
D3 = np.array([[5.1,36,76],[7.0,52,85],[8.1,47,102],[14.5,50,88],[18.5,63,112],[22.8,71,147],[27.3,67,155],[27.5,71,130],[25.1,68,107],[19.5,61,84],[14.9,58,90],[7.5,48,99],[4.8,43,69],[5.4,49,81],[8.8,59,92],[14.5,63,95],[19.6,65,96],[21.4,73,122],[26.4,75,160],[29.1,69,123],[26.2,73,96],[19.4,65,100],[12.7,58,82],[7.3,52,145],[5.5,47,76],[6.2,48,87],[12.1,55,101],[15.2,55,102],[19.8,61,107],[22.9,74,136],[27.3,73,128],[29.2,70,144],[25.2,69,98],[19.8,72,88],[13.5,55,89],[8.3,52,109],[6.3,45,97],[5.9,52,95],[10.4,52,121],[15.0,56,101],[20.3,62,98],[23.4,75,145],[26.8,74,139],[27.7,74,114],[23.2,68,95],[19.1,67,97],[14.2,63,84],[6.7,55,94],[5.8,52,86],[5.7,59,82],[10.3,57,89],[14.5,71,84],[21.1,62,94],[22.1,75,125],[26.2,80,150],[26.7,78,131],[22.6,79,104],[18.4,66,87],[13.9,74,84],[9.3,57,119],[6.1,55,82],[7.2,56,89],[10.1,61,98],[15.4,67,98],[20.2,66,121],[22.4,75,150],[25.4,80,150],[27.1,78,143],[24.4,86,102],[18.7,72,107],[11.4,71,98],[8.9,59,110],[5.8,53,96],[6.9,49,92],[8.5,60,106],[14.7,66,95],[20.0,72,115],[22.0,73,156],[27.3,78,153],[26.4,83,125],[22.8,79,104],[16.8,82,105],[11.9,67,93],[6.6,56,144],
              [4.7,54,94],[5.4,56,93],[11.5,65,106],[17.0,66,98],[19.8,71,109],[22.4,80,160],[28.3,77,215],[28.1,77,164],[22.9,86,126],[19.1,74,124],[14.0,72,108],[8.3,61,128],[5.6,51,108],[7.2,59,103],[10.6,60,115],[13.6,63,111],[20.0,65,132],[21.8,81,163],[24.1,89,148],[28.4,80,141],[25.1,79,137],[19.4,80,113],[13.1,69,93],[8.5,66,111],[7.1,65,94],[8.3,55,99],[10.7,65,109],[12.8,66,109],[19.5,75,108],[23.2,82,160],[24.3,89,137],[29.1,76,150],[24.2,83,115],[17.5,75,101],[14.0,65,98],[7.7,61,118]])
D3_kenshou = np.array([[5.4,57,92],[8.5,49,88],[12.8,62,97],[15.1,60,113],[19.6,73,117],[22.7,77,148],[25.9,83,165],[27.4,80,130],[22.3,82,119],[18.2,76,110],[13.7,65,103],[7.9,60,119],[4.9,52,105],[5.2,53,103],[10.9,63,99],[15.3,75,99],[18.8,75,130],[23.0,77,156],[27.4,79,149],[27.5,79,136],[24.4,81,113],[17.2,75,109],[14.5,70,107],[7.5,60,93]])
def draw_step1(ax, eta, xt, yt, grad, w, X, X_test, y_test):
    def f(x):
      return w[0] + w[1] * x + w[2] * (x ** 2) + w[3] * (x ** 3)

    artist = []
    x = np.arange(0, 30, 0.001)
    artist.extend(ax.plot(x, f(x), color='black'))
    artist.extend(ax.plot([xt], [yt], 'ro'))
    artist.append(ax.text(xt, yt, "$L_D = {}$".format(np.linalg.norm(y - np.dot(X,w), ord=2) ** 2), ha='right'))
    artist.append(ax.text(xt, yt + 0.5, "$L_D2 = {}$".format(np.linalg.norm(y_test - np.dot(X_test,w), ord=2) ** 2), ha='right'))
    return artist
max_epochs = 10000
eta0 = 1
eps = 1e-5

X = np.vstack([np.ones_like(D3[:,1]), D3[:,1], D3[:,1] ** 2, D3[:,1] ** 3]).T
X_test = np.vstack([np.ones_like(D3_kenshou[:,1]), D3_kenshou[:,1], D3_kenshou[:,1] ** 2, D3_kenshou[:,1] ** 3]).T
y = D3[:,2]
y_test = D3_kenshou[:,2]
w = np.ones(X.shape[1]) / 10000

#x = np.linspace(0, 1.5, 1000)

fig, ax = plt.subplots(dpi=100, figsize=(6, 6))
ax.scatter(D3[:,0], D3[:,2], marker='o', color='b')
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.set_xlim(0, 30)
ax.set_ylim(0, 180)
ax.set_aspect('auto')
ax.grid()

artists = []
for t in range(max_epochs):
    eta = eta0 / np.sqrt(1+t)
    i = np.random.randint(0, X.shape[0])
    y_hat = np.dot(X[i], w)
    grad = 2 * (eta * y_hat - eta * y[i]) * X[i]
    if np.sum(np.abs(grad)) < eps:
        artists.append(draw_step1(ax, eta, x_t, y_hat, grad, w, X, X_test))
        break
    w -= grad
    x_t = X[i, 1]
    if t % 100 == 0:
      artists.append(draw_step1(ax, eta, x_t, y_hat, grad, w, X, X_test, y_test))

ani = matplotlib.animation.ArtistAnimation(fig, artists, interval=100)
html = ani.to_jshtml()
plt.close(fig)
HTML(html)
<ipython-input-226-939e215fe1fc>:27: RuntimeWarning: overflow encountered in multiply
  grad = 2 * (eta * y_hat - eta * y[i]) * X[i]
<ipython-input-226-939e215fe1fc>:31: RuntimeWarning: invalid value encountered in subtract
  w -= grad
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values
WARNING:matplotlib.text:posx and posy should be finite values

このように、計算途中でオーバーフローしてしまった。

考えられる原因は、価格がそれなりに大きな値を取理、また学習率\(\eta_t\)も小さな値を取るため、計算している途中で重みが大きな値になり、値が発散してしまったことである。

また、今回とってきたデータ対には関係性が見られず、重みが修正されるたびに極端な値をラざるを得なくなって発散してしまうのかもしれない。

この課題では、マクローリン展開の係数を実際の値から求める回帰モデルを検討し、その精度について議論した。 一方で実用的な回帰にはきちんと応用できなかった。